/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import business.UserLogin;
import data.LoginUserDBase;

/**
 *
 * @author User
 */
public class LoginServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {
        // get parameters from the request

        String pass = request.getParameter("pass");
        String email = request.getParameter("email");

        // create the User object
        UserLogin user = new UserLogin();
        user.setEmail(email);
        user.setPass(pass);

        String url = "";
        String message = "";

        if (LoginUserDBase.cekUser(email, pass) == true) {
        //if (true == true) {
           LoginUserDBase.selectUser(email, pass);
           url="/home-member.jsp";
        }else{
            message="your email and password were wrong!";
            url = "/home.jsp";
        }


        // store the user and message in the session
        HttpSession session = request.getSession(true);
        session.putValue("user", email);
        request.setAttribute("message", message);

        // forward the request and response to the view
        RequestDispatcher dispatcher =
                getServletContext().getRequestDispatcher(url);
        dispatcher.forward(request, response);
    }
}
